FROM registry.cn-hangzhou.aliyuncs.com/hongxuan/golang-alpine:latest AS builder

LABEL stage=gobuilder

ENV CGO_ENABLED 0

RUN yum update  -y && yum install  epel-release git  protobuf-compiler -y
# 设置Go模块代理
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct

RUN go install github.com/zeromicro/go-zero/tools/goctl@latest
# 安装 protoc-gen-go 和 protoc-gen-go-grpc
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2

WORKDIR /build

RUN git clone https://gitee.com/HongXuandaozun/pone.git
# 切换目录到项目里面
WORKDIR /build/pone
RUN goctl rpc protoc pone.proto --go_out=. --go-grpc_out=. --zrpc_out=.

RUN go mod tidy

RUN go build -ldflags="-s -w" -o /app/pone .


FROM scratch

ENV TZ Asia/Shanghai

WORKDIR /app
COPY --from=builder /app/pone /app/pone
COPY --from=builder /build/pone/etc /app/etc
EXPOSE 8080
CMD ["./pone", "-f", "etc/pone.yaml"]
